package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseDeploymentResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DeploymentResourceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DeploymentResponse;
import java.io.File;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.DeploymentApi")
public class DeploymentApi {
    private ApiClient apiClient;

    public DeploymentApi() {
        this(new ApiClient());
    }

    @Autowired
    public DeploymentApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Delete a deployment
     *
     * <p><b>204</b> - Indicates the deployment was found and has been deleted. Response-body is intentionally empty.
     * <p><b>404</b> - Indicates the requested deployment was not found.
     * @param deploymentId The deploymentId parameter
     * @param cascade The cascade parameter
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public void deleteDeployment(String deploymentId, Boolean cascade) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'deploymentId' is set
        if (deploymentId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'deploymentId' when calling deleteDeployment");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("deploymentId", deploymentId);
        String path = UriComponentsBuilder.fromPath("/repository/deployments/{deploymentId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "cascade", cascade));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
        apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get a deployment
     *
     * <p><b>200</b> - Indicates the deployment was found and returned.
     * <p><b>404</b> - Indicates the requested deployment was not found.
     * @param deploymentId The id of the deployment to get.
     * @return DeploymentResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DeploymentResponse getDeployment(String deploymentId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'deploymentId' is set
        if (deploymentId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'deploymentId' when calling getDeployment");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("deploymentId", deploymentId);
        String path = UriComponentsBuilder.fromPath("/repository/deployments/{deploymentId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DeploymentResponse> returnType = new ParameterizedTypeReference<DeploymentResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get a deployment resource
     * Replace ** by ResourceId
     * <p><b>200</b> - Indicates both deployment and resource have been found and the resource has been returned.
     * <p><b>404</b> - Indicates the requested deployment was not found or there is no resource with the given id present in the deployment. The status-description contains additional information.
     * @param deploymentId The deploymentId parameter
     * @return DeploymentResourceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DeploymentResourceResponse getDeploymentResource(String deploymentId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'deploymentId' is set
        if (deploymentId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'deploymentId' when calling getDeploymentResource");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("deploymentId", deploymentId);
        String path = UriComponentsBuilder.fromPath("/repository/deployments/{deploymentId}/resources/**").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DeploymentResourceResponse> returnType = new ParameterizedTypeReference<DeploymentResourceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get a deployment resource content
     * The response body will contain the binary resource-content for the requested resource. The response content-type will be the same as the type returned in the resources mimeType property. Also, a content-disposition header is set, allowing browsers to download the file instead of displaying it.
     * <p><b>200</b> - Indicates both deployment and resource have been found and the resource data has been returned.
     * <p><b>404</b> - Indicates the requested deployment was not found or there is no resource with the given id present in the deployment. The status-description contains additional information.
     * @param deploymentId The deploymentId parameter
     * @param resourceName The name of the resource to get. Make sure you URL-encode the resourceName in case it contains forward slashes. Eg: use diagrams%2Fmy-process.bpmn20.xml instead of diagrams/my-process.bpmn20.xml.
     * @return List&lt;byte[]&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<byte[]> getDeploymentResourceData(String deploymentId, String resourceName) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'deploymentId' is set
        if (deploymentId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'deploymentId' when calling getDeploymentResourceData");
        }

        // verify the required parameter 'resourceName' is set
        if (resourceName == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'resourceName' when calling getDeploymentResourceData");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("deploymentId", deploymentId);
        uriVariables.put("resourceName", resourceName);
        String path = UriComponentsBuilder.fromPath("/repository/deployments/{deploymentId}/resourcedata/{resourceName}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<byte[]>> returnType = new ParameterizedTypeReference<List<byte[]>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List resources in a deployment
     * The dataUrl property in the resulting JSON for a single resource contains the actual URL to use for retrieving the binary resource.
     * <p><b>200</b> - Indicates the deployment was found and the resource list has been returned.
     * <p><b>404</b> - Indicates the requested deployment was not found.
     * @param deploymentId The deploymentId parameter
     * @return List&lt;DeploymentResourceResponse&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<DeploymentResourceResponse> listDeploymentResources(String deploymentId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'deploymentId' is set
        if (deploymentId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'deploymentId' when calling listDeploymentResources");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("deploymentId", deploymentId);
        String path = UriComponentsBuilder.fromPath("/repository/deployments/{deploymentId}/resources").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<DeploymentResourceResponse>> returnType = new ParameterizedTypeReference<List<DeploymentResourceResponse>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List Deployments
     *
     * <p><b>200</b> - Indicates the request was successful.
     * @param name Only return deployments with the given name.
     * @param nameLike Only return deployments with a name like the given name.
     * @param category Only return deployments with the given category.
     * @param categoryNotEquals Only return deployments which do not have the given category.
     * @param parentDeploymentId Only return deployments with the given parent deployment id.
     * @param parentDeploymentIdLike Only return deployments with a parent deployment id like the given value.
     * @param tenantId Only return deployments with the given tenantId.
     * @param tenantIdLike Only return deployments with a tenantId like the given value.
     * @param withoutTenantId If true, only returns deployments without a tenantId set. If false, the withoutTenantId parameter is ignored.
     * @param sort Property to sort on, to be used together with the order.
     * @return DataResponseDeploymentResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseDeploymentResponse listDeployments(String name, String nameLike, String category, String categoryNotEquals, String parentDeploymentId, String parentDeploymentIdLike, String tenantId, String tenantIdLike, Boolean withoutTenantId, String sort) throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/repository/deployments").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "name", name));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "nameLike", nameLike));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "category", category));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "categoryNotEquals", categoryNotEquals));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "parentDeploymentId", parentDeploymentId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "parentDeploymentIdLike", parentDeploymentIdLike));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantId", tenantId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantIdLike", tenantIdLike));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "withoutTenantId", withoutTenantId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "sort", sort));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseDeploymentResponse> returnType = new ParameterizedTypeReference<DataResponseDeploymentResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Create a new deployment
     * The request body should contain data of type multipart/form-data. There should be exactly one file in the request, any additional files will be ignored. The deployment name is the name of the file-field passed in. If multiple resources need to be deployed in a single deployment, compress the resources in a zip and make sure the file-name ends with .bar or .zip.  An additional parameter (form-field) can be passed in the request body with name tenantId. The value of this field will be used as the id of the tenant this deployment is done in.
     * <p><b>200</b> - successful operation
     * <p><b>201</b> - Indicates the deployment was created.
     * <p><b>400</b> - Indicates there was no content present in the request body or the content mime-type is not supported for deployment. The status-description contains additional information.
     * @param file The file parameter
     * @param deploymentKey The deploymentKey parameter
     * @param deploymentName The deploymentName parameter
     * @param tenantId The tenantId parameter
     * @return DeploymentResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DeploymentResponse uploadDeployment(File file, String deploymentKey, String deploymentName, String tenantId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'file' is set
        if (file == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'file' when calling uploadDeployment");
        }

        String path = UriComponentsBuilder.fromPath("/repository/deployments").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "deploymentKey", deploymentKey));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "deploymentName", deploymentName));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantId", tenantId));

        if (file != null)
            formParams.add("file", new FileSystemResource(file));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = {
            "multipart/form-data"
        };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DeploymentResponse> returnType = new ParameterizedTypeReference<DeploymentResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
